﻿using System;
using System.Text;
using UnityEngine;
using XLua;

namespace Yoozoo.Gameplay.RTS.Proto
{
    [GCOptimize]
    [LuaCallCSharp]
    public struct TroopMarchL3
    {
        // 不可变
        public long tid;
        public int hero1;
        public int hero2;
        public int hero3;

        public long playerId;
        // 可变
        public Coordinate coordinate;
        public Coordinate[] pathList;
        public long targetId;
        public long lastFrameTime;
        
        //来自服务器的speed数据： m/h
        public float speed;
        public int marchStatusInt;
        //public string allianceCode;
        public Coordinate targetPosition;

        public long attackTargetId;
        // Lua层计算/查表得到
        public int team;
        public string[] heroIconList;
        public int rageMaxList;
        public int[] heroRageList;
        public int targetTeam;
        public int[] heroQualityList;
        public MapUnit attachUnit;
        public int soldierType;
        public bool visible;
        public int clientStatusInt;
        public CrossingGate crossDetail;
        public float radius;

        //夹击用，lua传过来的
        //夹击的圆心
        public Vector3 besiegeCenter;
        //夹击的半径
        public float besiegeRadius;
        /// <summary>
            /* 夹击移动的最终角度 当值为-2.0时 客户端需要预判部队的夹击位置 平滑夹击移动
         -2.0: 表示部队还未寻找夹击角度 默认值/取消对目标的夹击时赋值为-2.0
         -1.0: 表示部队夹击移动结束 已移动到夹击位
          >0: 表示部队在夹击移动中 value表示夹击移动的最终角度*/
        /// </summary>
        public double besiegeFinalAngle;
        public float besiegeSpeedRatio;
        public TargetCoordinateType attackTargetType;
        public TargetCoordinateType targetType;
        public TargetCoordinateType troopType;
        
        //货车相关
        public int truckColor;
        public int truckBeGrabbedTimes;

        public long serverWorldId;
        
        [BlackList]
        public EMarchStatus ClientStatus
        {
            get
            {
                return (EMarchStatus)clientStatusInt;
            }
        }

        [BlackList]
        public TargetCoordinateType TargetType
        {
            get
            {
                return (TargetCoordinateType)targetType;
            }
        }

        [BlackList]
        public MarchStatus MarchStatus
        {
            get
            {
                return (MarchStatus)marchStatusInt;
            }
        }

        public string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("tid:" + tid);
            sb.AppendLine("--> lastFrameTime:" + lastFrameTime);
            sb.AppendLine("--> speed:" + speed);
            sb.AppendLine("--> marchStatus:" + Enum.GetName(typeof(MarchStatus),marchStatusInt));
            return sb.ToString();
        }

        [BlackList]
        public bool IsCrossingGate
        {
            get
            {
                if (crossDetail.startTime == 0 || crossDetail.startTime + BattleUtils.CrossingGateTime * 1000 < TimeUtils.GetServerTimeMs())
                {
                    return false;
                }
                return true;
            }
        }
    }
}
